package com.tianbo.service.imp;

import com.tianbo.common.ModelAndPage;
import com.tianbo.mapper.TOlapColumnMapper;
import com.tianbo.model.TOlapColumn;
import com.tianbo.model.TOlapColumnExample;
import com.tianbo.service.OlapColumnService;
import com.tianbo.util.dao.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.util.List;

/**
 * Created by Mr.Xu on 2017/9/11.
 */
@Service
public class OlapColumnImpl implements OlapColumnService {
    @Autowired
    private TOlapColumnMapper tOlapColumnMapper;

    public ModelAndPage findOlapColumn(int start, int pagelenth) throws Exception {
        TOlapColumnExample tOlapColumn = new TOlapColumnExample();
        Page page=new Page(start,pagelenth);
        tOlapColumn.setPage(page);
        int count=tOlapColumnMapper.countByExample(tOlapColumn);
        page.setCount(count);
        List<TOlapColumn> tOlapColumnList = tOlapColumnMapper.selectByExample(tOlapColumn);
        ModelAndPage<TOlapColumn> modelAndPage=new ModelAndPage<TOlapColumn>(tOlapColumnList,page);
        return modelAndPage;
    }
    public List<TOlapColumn> selectOlapColumn(BigDecimal datasetid)throws Exception{
        TOlapColumnExample tOlapColumnExample=new TOlapColumnExample();
        tOlapColumnExample.createCriteria().andDatasetidEqualTo(datasetid);
        List<TOlapColumn> tOlapColumnList=tOlapColumnMapper.selectByExample(tOlapColumnExample);
        return tOlapColumnList;
    }
    public List<TOlapColumn> findOlapColumn()throws Exception{
        TOlapColumnExample tOlapColumnExample=new TOlapColumnExample();
        List<TOlapColumn> tOlapColumnList=tOlapColumnMapper.selectByExample(tOlapColumnExample);
        return tOlapColumnList;
    }
    public void addOlapColumn(TOlapColumn tOlapColumn) {
        tOlapColumnMapper.insert(tOlapColumn);
    }

    public int deleteOlapColumn(BigDecimal datasetid) {
        TOlapColumnExample tOlapColumnExample = new TOlapColumnExample();
        tOlapColumnExample.createCriteria().andDatasetidEqualTo(datasetid);
        tOlapColumnMapper.deleteByExample(tOlapColumnExample);
        return 1;
    }

    public void deleteByPrimaryKey(BigDecimal columnid) {
        tOlapColumnMapper.deleteByPrimaryKey(columnid);
    }

    public TOlapColumn findByid(BigDecimal columnid) throws Exception {
        TOlapColumn olapColumn = new TOlapColumn();
        olapColumn = tOlapColumnMapper.selectByPrimaryKey(columnid);
        return olapColumn;
    }

    public void updateOlapColumn(TOlapColumn olapColumn) {
        tOlapColumnMapper.updateByPrimaryKey(olapColumn);
    }
}
